<?php
 /*************************************************\
    TV-Program
    Version: 2.5
    Author: Dmitri M. Furmanoff
    E-mail: furik@mail.ru
    \*************************************************/

    /*************************************************\
    Компонент: Телепрограммы
    Версия: 2.5
    Автор: Дмитрий Фурманов
    E-mail: furik@mail.ru
    \*************************************************/

defined ('_VALID_MOS') or die('Доступ к файлу запрещен.');
require_once($mosConfig_absolute_path."/administrator/components/com_tv/config.tv.php");

if($my->id)
{
$remfile=$mosConfig_absolute_path."/components/com_tv/reminder/rem.db";
$remstr="";
$today=getdate(time()+($mosConfig_offset*60*60));
$dayofweek = $today['wday']; 
$dayofweek=$dayofweek?$dayofweek:7;
$i=0;

$qr = "SELECT email, name FROM #__users WHERE id = ".$my->id." LIMIT 0,1";
$database->setQuery( $qr );
 if(!$database->query()) {
		echo $database->stderr( true );
		return;
	}
	$Rows = $database->loadObjectList(); 
if(count($Reminder)){
foreach($Reminder as $k=>$v) 
    {
    $rem[$k]=intval($v);
    }
$wh=implode(",",$rem);
$qr="select * from #__tvprogramms p inner join #__tvchannels c on p.channel=c.cid where pid in (".$wh.")";
$database->setQuery($qr);
if(!$database->query()) {
		echo $database->stderr( true );
		return;
	}
$programms=$database->loadObjectList();

if(!$fp=fopen("$remfile","a+")){
  echo _TV_REMINDERERROR;
   return;  
}
$List=file("$remfile");
foreach($programms as $program)
{
$eq=0;
$srem= $program->date."|".$Rows[0]->email."|".$Rows[0]->name."|".$program->hour."|".$program->minute."|".$program->channelname."|".$program->name."\n";
foreach($List as $line)
 {
 if(trim($line)==trim($srem))
   $eq=1;
 }
if(!$eq)
 $remstr.=$srem;
}

fputs($fp, $remstr, strlen($remstr));
fclose ($fp);  
chmod("$remfile",0660);

echo _TV_REMINDERDONE;
}
else
   echo _TV_REMINDERNOPOG;
}


// Draw the Back button.
mosHTML::BackButton( $params ); 
?>
